//
//  SLAddShippingViewController.m
//  StarLight
//
//  Created by apple on 16/8/28.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLAddShippingViewController.h"
#import <STPopup/STPopup.h>
#import "SLAddShippingTableViewCell.h"
#import "SLAddBoatViewController.h"


@interface SLAddShippingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UIView *headView;

@property (nonatomic ,strong) UIView *bottomView;

@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) UILabel *titleLb;

@property (nonatomic ,strong) UIButton *addBtn;

@property (nonatomic ,strong) UIButton *cancelBtn;

@end

@implementation SLAddShippingViewController

- (instancetype)init{
    if (self = [super init]) {
        self.contentSizeInPopup = CGSizeMake(300 *MIX_W, 200 * MIX_H);
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addUI];
    
    // Do any additional setup after loading the view.
}

- (void)dismissVC{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)addShipping{
    if (self.addUpViewBlock) {
        [self dismissViewControllerAnimated:YES completion:nil];
        self.addUpViewBlock();
    }
}


- (void)addUI{
    [self.view addSubview:self.headView];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self.headView addSubview:self.titleLb];
    [self.bottomView addSubview:self.addBtn];
    [self.bottomView addSubview:self.cancelBtn];
    
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(45 *MIX_H);
        make.top.width.equalTo(self.view);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headView.mas_bottom);
        make.width.equalTo(self.headView);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom);
        make.width.equalTo(self.headView);
        make.bottom.equalTo(self.view);
    }];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.equalTo(self.headView);
    }];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.bottom.equalTo(self.bottomView);
        make.width.mas_equalTo(150 *MIX_W);
        make.centerY.equalTo(self.bottomView);
    }];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addBtn.mas_right);
        make.top.bottom.equalTo(self.bottomView);
        make.width.mas_equalTo(150 *MIX_W);
        make.centerY.equalTo(self.bottomView);
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SLAddShippingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[SLAddShippingTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.updateUpViewBlock) {
        [self dismissViewControllerAnimated:YES completion:nil];
        self.updateUpViewBlock();
    }
}


- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 110 * MIX_H / 3.0;
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
- (UIView *)headView{
    
    if (!_headView) {
        _headView = [UIView new];
    }
    return _headView;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [UIView new];
    }
    return _bottomView;
}

- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [UILabel new];
        _titleLb.text = @"选择更新船舶";
        _titleLb.font = sFont(16);
    }
    return _titleLb;
}

- (UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [UIButton new];
        [_addBtn setTitle:@"添加" forState:(UIControlStateNormal)];
        [_addBtn setTitleColor:RGBCOLOR(0, 0, 0) forState:(UIControlStateNormal)];
        [_addBtn addTarget:self action:@selector(addShipping) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _addBtn;
}

- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton new];
        [_cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
        [_cancelBtn setTitleColor:RGBCOLOR(0, 0, 0) forState:(UIControlStateNormal)];
        [_cancelBtn addTarget:self action:@selector(dismissVC) forControlEvents:(UIControlEventTouchUpInside)];
        
    }
    return _cancelBtn;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
